package com.calciominoBeta.Activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.calciomio.app.R;
import com.calciominoBeta.Activity.db.DbSupport;
import com.calciominoBeta.Fragment.ListNewsFragment;
import com.calciominoBeta.SlidingMenu.SampleListFragment;
import com.calciominoBeta.Util.MyUrl;
import com.calciominoBeta.Util.Util;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;

public class Main_Activity extends Base_Activity {

	private Fragment mContent;
	ImageView img_refresh;
	RelativeLayout rl_refresh;
	Animation animation_refresh;
	private InterstitialAd interstitial;

	public Main_Activity() {
		super(R.string.demo);
	}
	
	
	

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	
		interstitial = new InterstitialAd(Main_Activity.this);
		interstitial.setAdUnitId(getString(R.string.interstitial));
		AdRequest adRequest = new AdRequest.Builder()
		.addTestDevice(AdRequest.DEVICE_ID_EMULATOR).addTestDevice("")
		.build();
		interstitial.loadAd(adRequest);
		interstitial.setAdListener(new AdListener() {
			@Override
			public void onAdLoaded() {
				if (interstitial.isLoaded()) {
					interstitial.show();
				}
			}
		});

		DbSupport.initDb(Main_Activity.this);
		rl_refresh=(RelativeLayout)findViewById(R.id.rl_refresh);
		
		rl_refresh.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ListNewsFragment listNewsFragment = new ListNewsFragment(
						ListNewsFragment.url);
				setContentView(R.layout.content_frame);
				getSupportFragmentManager().beginTransaction()
						.replace(R.id.content_frame, listNewsFragment).commit();
			}
		});
		img_refresh = (ImageView) findViewById(R.id.img_refesh);
		ImageView[] img={img_refresh,};
		Util.hilightBtn(img);
		img_refresh.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ListNewsFragment listNewsFragment = new ListNewsFragment(
						ListNewsFragment.url);
				setContentView(R.layout.content_frame);
				getSupportFragmentManager().beginTransaction()
						.replace(R.id.content_frame, listNewsFragment).commit();
				
			}
		});
		// setSlidingActionBarEnabled(true);
		if (savedInstanceState != null)
			mContent = getSupportFragmentManager().getFragment(
					savedInstanceState, "mContent");

		if (mContent == null)
			mContent = new ListNewsFragment(MyUrl.HOME);

		// BaseNetSupportBeta.getInstance()

		// set the Above
		setContentView(R.layout.content_frame);
		getSupportFragmentManager().beginTransaction()
				.replace(R.id.content_frame, mContent).commit();

		// set the Behind View
		setBehindContentView(R.layout.menu_frame);
		getSupportFragmentManager().beginTransaction()
				.replace(R.id.menu_frame, new SampleListFragment()).commit();
	}

	




	public void switchContent(Fragment fragment) {
		mContent = fragment;
		getSupportFragmentManager().beginTransaction()
				.replace(R.id.content_frame, fragment).commit();
		getSlidingMenu().showContent();
	}
}
